package com.videoweb.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.videoweb.mapper.DanmakuMapper;
import com.videoweb.model.Danmaku;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class DanmakuService extends ServiceImpl<DanmakuMapper, Danmaku> {
    @Autowired
    private DanmakuMapper danmakuMapper;
    
    public Danmaku createDanmaku(Long videoId, String content, Double timestamp, 
                                String position, String color, Integer size, String sender) {
        Danmaku danmaku = new Danmaku();
        danmaku.setVideoId(videoId);
        danmaku.setContent(content);
        danmaku.setTimestamp(timestamp);
        danmaku.setPosition(position);
        danmaku.setColor(color);
        danmaku.setSize(size);
        danmaku.setSender(sender);
        danmaku.setCreatedAt(LocalDateTime.now());
        
        danmakuMapper.insert(danmaku);
        return danmaku;
    }
    
    public List<Danmaku> getDanmakusByVideoId(Long videoId) {
        return danmakuMapper.findByVideoIdOrderByTimestampAsc(videoId);
    }
}
